home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12232 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  47 lines

  1. Path: newshost.cyberramp.net!news
  2. From: sinan@cyberramp.net (John Noland)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Int to Double, Pl Advise!
  5. Date: 29 Mar 1996 23:32:07 GMT
  6. Organization: Prose Software
  7. Message-ID: <4jhrtn$3nr@newshost.cyberramp.net>
  8. References: <isa5224.544.315B647A@age2.age.uiuc.edu>
  9. NNTP-Posting-Host: ramp3-11.cyberramp.net
  10. X-Newsreader: WinVN 0.99.5
  11.  
  12. In article <isa5224.544.315B647A@age2.age.uiuc.edu>, isa5224@age2.age.uiuc.edu says...
  13.  
  14. >I am having problems with the following type conversion.  From int to double.  
  15. >If someone can comment:
  16. >
  17. >#define Ng 4
  18. >#define Nr 4
  19. >
  20. >#include <stdio.h>
  21. >#include <math.h>
  22. >#include <malloc.h> 
  23. >
  24. >int p0[Ng][Nr];
  25. >
  26. >int main(){
  27. >int i,j,k;  
  28. >float x =0;
  29. >float y =0; 
  30. >:
  31. >:
  32. >:
  33. >for (i=1; i<Ng; i++) { 
  34. >        for (j=1; j<Nr; j++) {
  35. >   
  36. >         x = x + ((double) p0[i,j]) / (double)(j*j); }
  37.                               ^^^^^
  38. This isn't the correct notation for accessing an element of a two dimensional 
  39. array. Instead of [i ,j], try [i][j]. 
  40.  
  41. >}
  42. >
  43. >I get the following compilation error(s) on MS C++ compiler:
  44. >error C2440: 'cast' : cannot convert from 'int [4]' to 'double '
  45.  
  46.  
  47.